package com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment;

import android.os.Bundle;
import android.view.View;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.freak.neteasecloudmusic.R;
import com.freak.neteasecloudmusic.base.BaseAbstractMvpActivity;
import com.freak.neteasecloudmusic.base.BaseAbstractMvpWithPlayerActivity;
import com.freak.neteasecloudmusic.base.IActivityStatusBar;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment.adapter.CommentAdapter;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment.entity.CommentEntity;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment.entity.CommentHeadEntity;
import com.freak.neteasecloudmusic.modules.find.recommend.songlist.detail.comment.entity.CommentTypeEntity;
import com.freak.neteasecloudmusic.utils.ToastUtil;
import com.freak.neteasecloudmusic.view.custom.toolbar.SimpleToolbar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Freak on 2020/3/7.
 * 歌单评论
 */
public class CommentActivity extends BaseAbstractMvpActivity<CommentPresenter> implements CommentContract.View, IActivityStatusBar {
    @BindView(R.id.recyclerViewComment)
    RecyclerView recyclerViewComment;
    @BindView(R.id.simpleToolbarComment)
    SimpleToolbar simpleToolbarComment;
    private Bundle mBundle;
    private String id;
    private int limit = 20;
    private int offset = 0;
    private List<MultiItemEntity> mMultiItemEntityList;
    private CommentAdapter mCommentAdapter;
    private CommentHeadEntity mCommentHeadEntity;

    @Override
    protected int getLayout() {
        return R.layout.activity_comment;
    }

    @Override
    protected void initEventAndData() {
        mPresenter.getCommentList(mCommentHeadEntity.getId(), String.valueOf(limit), String.valueOf(offset), "");
    }

    @Override
    protected void onCreateLoadData() {

    }

    @Override
    protected void onDestroyRelease() {

    }

    @Override
    protected void onResumeLoadData() {

    }

    @Override
    protected void initView() {
        simpleToolbarComment.setLeftIconClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        }).setRightIconClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        mBundle = getIntent().getExtras();
        if (mBundle == null) {
            finish();
            return;
        }
        mCommentHeadEntity = mBundle.getParcelable("mCommentHeadEntity");
        mMultiItemEntityList = new ArrayList<>();
        recyclerViewComment.setLayoutManager(new LinearLayoutManager(mActivity));
        mCommentAdapter = new CommentAdapter(mMultiItemEntityList, mActivity);
        mCommentAdapter.bindToRecyclerView(recyclerViewComment);
        mCommentAdapter.setEmptyView(R.layout.view_no_data_common, recyclerViewComment);
        mCommentAdapter.disableLoadMoreIfNotFullPage();
        recyclerViewComment.setAdapter(mCommentAdapter);
    }

    @Override
    protected CommentPresenter createPresenter() {
        return new CommentPresenter();
    }

    @Override
    public void showToast(String toast) {
        ToastUtil.shortShow(toast);
    }

    @Override
    public int getStatusBarColor() {
        return ContextCompat.getColor(this, R.color.color_white);
    }

    @Override
    public int getDrawableStatusBar() {
        return 0;
    }

    @Override
    public void getCommentListSuccess(CommentEntity commentEntity) {
        if (offset == 0) {
            mMultiItemEntityList.add(mCommentHeadEntity);
        }
        if (commentEntity != null) {
            if (commentEntity.getHotComments() != null && commentEntity.getHotComments().size() > 0) {
                CommentTypeEntity hotCommentTypeEntity = new CommentTypeEntity();
                hotCommentTypeEntity.setTypeName("精彩评论");
                mMultiItemEntityList.add(hotCommentTypeEntity);
                mMultiItemEntityList.addAll(commentEntity.getHotComments());
            }
            if (commentEntity.getTopComments() != null && commentEntity.getTopComments().size() > 0) {
                CommentTypeEntity topCommentTypeEntity = new CommentTypeEntity();
                topCommentTypeEntity.setTypeName("最新评论");
                topCommentTypeEntity.setCount(String.valueOf(commentEntity.getTopComments().size()));
                mMultiItemEntityList.add(topCommentTypeEntity);
                mMultiItemEntityList.addAll(commentEntity.getTopComments());
            }

            if (commentEntity.getComments() != null && commentEntity.getComments().size() > 0) {
                mMultiItemEntityList.addAll(commentEntity.getComments());
            }
        }
        mCommentAdapter.notifyDataSetChanged();
    }

}
